﻿using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using Entities;
using Utility;
using BUS;


public partial class Administrator_Khachhang_ds : System.Web.UI.Page
{
    public int stt;
    protected void Page_Load(object sender, EventArgs e)
    {
        if (!IsPostBack)
        {
            load_data();
        }
    }
    private void load_data()
    {
        PagerV2_1.PageSize = 15;
        Criteria c = new Criteria();

        int total = 0;
        if (txt_tenkhachhang.Text != "0")
        {
            c.add(Condition.AND, Tbl_KhachHang_Columns.TaiKhoan, Condition.LIKE,
               (txt_tenkhachhang.Text));
        }
        Tbl_KhachHang_Collection khCollection =
            Tbl_KhachHang_BUS.Get(c.Criter, PagerV2_1.CurrentIndex, PagerV2_1.PageSize,
            Tbl_KhachHang_Columns.STT.ToString(), OrderDirection.ASC.ToString(), out total);
        Repeater1.DataSource = khCollection;
        Repeater1.DataBind();

        PagerV2_1.ItemCount = total;
    }

    protected void Repeater1_ItemDataBound(object sender, RepeaterItemEventArgs e)
    {
        if (e.Item.ItemType == ListItemType.AlternatingItem ||
                  e.Item.ItemType == ListItemType.Item)
        {
            Tbl_KhachHang_Entities kh = (Tbl_KhachHang_Entities)e.Item.DataItem;
            HyperLink hyp_tendn = (HyperLink)e.Item.FindControl("hyp_tendn");
            Literal lit_diachi = (Literal)e.Item.FindControl("lit_diachi");
            Literal lit_sdt = (Literal)e.Item.FindControl("lit_sdt");
            Literal lit_hoten = (Literal)e.Item.FindControl("lit_hoten");
            Literal lit_email = (Literal)e.Item.FindControl("lit_email");
            Literal lit_sodu = (Literal)e.Item.FindControl("lit_sodu");
            HiddenField HiddenField1 = (HiddenField)e.Item.FindControl("HiddenField1");
            
            lit_diachi.Text = kh.DiaChi;
            lit_sdt.Text = kh.SDT;
            HiddenField1.Value =  kh.STT.ToString();
            lit_sodu.Text = kh.Sodutaikhoan.ToString();
            lit_email.Text=kh.Email;
            lit_hoten.Text = kh.HoTen;
            hyp_tendn.NavigateUrl = "~/Administrator/khachhang_ct.aspx?id=" + HiddenField1.Value;

            HyperLink hpl_hoadon = (HyperLink)e.Item.FindControl("hpl_hoadon");
            hpl_hoadon.NavigateUrl = "~/Administrator/dathang.aspx?kh=" + HiddenField1.Value;
            hpl_hoadon.ImageUrl = "~/GiaoDien/images/hoadon_icon.jpg";
            hpl_hoadon.ToolTip = "Xem hóa đơn";

            HyperLink hpl_sua = (HyperLink)e.Item.FindControl("hpl_sua");
            hpl_sua.ImageUrl = "~/GiaoDien/images/modify_icon.jpg";
            hpl_sua.NavigateUrl = "~/Administrator/khachhang_sua.aspx?id=" + HiddenField1.Value;
            hpl_sua.ToolTip = "Sửa thông tin";

            HyperLink hpl_xoa = (HyperLink)e.Item.FindControl("hpl_xoa");
            hpl_xoa.ImageUrl = "~/GiaoDien/images/del_icon.jpg";
            hpl_xoa.NavigateUrl = "~/Administrator/delete.aspx?idkhachhang=" + kh.STT.ToString();
            hpl_xoa.ToolTip = "Xóa đối tượng";
        }
    }
    protected void bt_timkiem_Click(object sender, EventArgs e)
    {
        load_data();
    }
}
